package com.his.back.service.serviceImpl;

import com.his.back.dao.*;
import com.his.back.pojo.*;
import com.his.back.service.ReceptionService;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ReceptionServiceImpl implements ReceptionService {


    @Autowired
    private memberMapper mM;
    @Autowired
    private patient_projectMapper ppM;
    @Autowired
    private ExPatientDrugMapper EPDM;

    @Autowired
    private invoiceMapper iM;
    @Autowired
    private registerLevelMapper rlM;
    @Autowired
    private departmentMapper dM;

    @Override
    public int addMember(member m) {
        return mM.insertSelective(m);
    }



    @Override
    public int registerInvoice(invoice inv) {
        return iM.insertSelective(inv);
    }

    @Override
    public ExMember findExMember(String patientId) {
        return mM.findExMember(patientId);
    }



    @Override
    public int pushPatient(String patientId) {
        member m=findExMember(patientId);
        m.setStateId(2);
        return mM.updateByPrimaryKeySelective(m);
    }

    @Override
    public List<ExPatientProject> findExPatiPro(String patientId, Integer stateId) {
        return ppM.findExPatiPro(patientId,stateId);
    }
    @Override
    public int insertPatiPro(patient_project pp) {
        return ppM.insertSelective(pp);
    }
    @Override
    public int deletePatiPro(patient_projectKey ppK) {
        return ppM.deleteByPrimaryKey(ppK);
    }

    @Override
    public List<ExPatientDrug> findExPatiDrug(String patientId,Integer stateId) {
        return EPDM.findExPatiDrug(patientId,stateId);
    }

    @Override
    public int updatePatiPro(patient_project pp) {
        return ppM.updateByPrimaryKeySelective(pp);
    }

    @Override
    public int updatePatiDrug(ExPatientDrug EPD) {
        return EPDM.updateByPrimaryKeySelective(EPD);
    }

    @Override
    public List<RelatedInvoice> findRelatedInvoice(String patientId) {
        List<RelatedInvoice> proInovices= ppM.findRelatedInvoice(patientId);
        List<RelatedInvoice> drugInovices= EPDM.findRelatedInvoice(patientId);
        proInovices.addAll(drugInovices);
        return proInovices;
    }

    @Override
    public List<ExPatientProject> findProDetail(String invoiceId) {
        return ppM.findProDetail(invoiceId);
    }

    @Override
    public List<ExPatientDrug> findDrugDetail(String invoiceId) {
        return EPDM.findDrugDetail(invoiceId);
    }

    @Override
    public int updateInvoice(invoice invoice) {
        return iM.updateByPrimaryKeySelective(invoice);
    }

    @Override
    public List<ExPatientDrug> findDrugCost(String patientId, Date startTime, Date endTime) {
        return EPDM.findDrugCost(patientId,startTime,endTime);
    }

    @Override
    public List<ExPatientProject> findProCost(String patientId,Date startTime, Date endTime) {
        return ppM.findProCost(patientId,startTime,endTime);
    }

    @Override
    public List<department> findDept() {
        return dM.selectAll();
    }


}

